package com.example.control

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView

class SettingsAdapter(val context: Context, val settingList: ArrayList<String>):
    RecyclerView.Adapter<SettingsAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        val settingName: TextView = view.findViewById(R.id.settingItemName)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.setting_item, parent, false)
        val holder = ViewHolder(view)
        holder.itemView.setOnClickListener {
            Toast.makeText(context, "Settings item clicked", Toast.LENGTH_SHORT).show()
        }
        return holder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val settingItem = settingList[position]
        println("settings test: ${settingItem.toString()}")
        holder.settingName.text = settingItem

    }

    override fun getItemCount(): Int {
        return settingList.size
    }
}